﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Word_Learner_3.Web;
using Word_Learner_3.Model;
using System.Collections.ObjectModel;
using System.Xml.Serialization;

namespace Word_Learner_3
{
    public partial class Property : Form
    {
        private int w_Top;

        private int w_Left;


        private int w_Interval;


        private bool w_TopMost;


        private double w_Opacity;

        private bool w_ReadOrNot;

        // public event loadProperty loadPropertyEvent;
        FloatingText f;
        Manager m;
        public void LoadProperty()
        {
            Config config = SerializationHelper.Load(typeof(Config), Application.StartupPath + "\\Configuration.config") as Config;
            w_Top = config.ConfigItem[0].Top;
            w_Left = config.ConfigItem[0].Left;
            w_Interval = config.ConfigItem[0].Interval;
            w_TopMost = config.ConfigItem[0].TopMost;
            w_ReadOrNot = config.ConfigItem[0].ReadOrNot;
            w_Opacity = config.ConfigItem[0].Opacity;
            switch (w_Interval)
            {
                case 1000: radioButton1.Checked = true; break;
                case 3000: radioButton2.Checked = true; break;
                case 5000: radioButton3.Checked = true; break;
                case 10000: radioButton4.Checked = true; break;
            }
            switch (w_TopMost)
            {
                case true: radioButton5.Checked = true; break;
                case false: radioButton6.Checked = true; break;

            }
            switch (w_ReadOrNot)
            {
                case true: radioButton7.Checked = true; break;
                case false: radioButton8.Checked = true; break;

            }
            trackBar1.Value = Convert.ToInt16(config.ConfigItem[0].Opacity);
            barValue.Text = Convert.ToInt16(config.ConfigItem[0].Opacity) + "%";


        }
        public Property(Manager m, FloatingText f)
        {
            InitializeComponent();

            LoadProperty();
            this.m = m;
            this.f = f;
        }





        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            barValue.Text = trackBar1.Value + "%";

        }



        private void saveProperty_Click(object sender, EventArgs e)
        {

            Config config = new Config();
            ConfigItem configItem = new ConfigItem();
            if (radioButton1.Checked == true)
            {
                configItem.Interval = 1000;
            }
            if (radioButton2.Checked == true)
            {
                configItem.Interval = 3000;
            }
            if (radioButton3.Checked == true)
            {
                configItem.Interval = 5000;
            }
            if (radioButton4.Checked == true)
            {
                configItem.Interval = 10000;
            }
            if (radioButton5.Checked == true)
            {
                configItem.TopMost = true;
            }
            if (radioButton6.Checked == true)
            {
                configItem.TopMost = false;

            }
            if (radioButton7.Checked == true)
            {
                configItem.ReadOrNot = true;
            }
            if (radioButton8.Checked == true)
            {
                configItem.ReadOrNot = false;

            }

            configItem.Top = f.Top;
            configItem.Left = f.Left;

            configItem.Opacity = trackBar1.Value;

            List<ConfigItem> configItemList = new List<ConfigItem>();
            configItemList.Add(configItem);
            config.ConfigItem = configItemList;

            SerializationHelper.Save(config, Application.StartupPath + "\\Configuration.config");
            //loadPropertyEvent.Invoke();


            loadProperty lp1 = new loadProperty(m.LoadProperty);
            lp1();
            loadProperty lp2 = new loadProperty(f.LoadProperty);
            lp2();
        }

        private void Property_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();


        }

        private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoadProperty();
        }
    }
}
